package com.activity.dao.impl;

import com.activity.bean.SuccessKilled;
import com.activity.bean.SuccessKilledExample;
import com.activity.dao.SuccessKilledDao;
import com.activity.mapper.SuccessKilledMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by wangzhanjin on 2017/12/26.
 */
@Repository
public class SuccessKilledDaoImpl implements SuccessKilledDao {

    @Autowired
    private SuccessKilledMapper successKilledMapper;

    public int insertSuccessKilled(long seckillId, long userPhone) {

        int i=0;
        try {
            SuccessKilled successKilled = new SuccessKilled();
            successKilled.setSeckillId(seckillId);
            successKilled.setState(Byte.decode("0"));
            successKilled.setUserPhone(userPhone);
            i = successKilledMapper.insertSelective(successKilled);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return i;
    }

    public SuccessKilled queryByIdWithSeckill(Long seckillId, long userPhone) {
        SuccessKilledExample example = new SuccessKilledExample();
        example.createCriteria().andSeckillIdEqualTo(seckillId).andUserPhoneEqualTo(userPhone);
        List<SuccessKilled> successKilleds = successKilledMapper.selectByExample(example);
        return successKilleds==null?null:successKilleds.get(0);
    }
}
